package top.yuyufeng.mbuy.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.yuyufeng.mbuy.dto.CartDTO;
import top.yuyufeng.mbuy.dto.ResponseJson;
import top.yuyufeng.mbuy.entity.Order;
import top.yuyufeng.mbuy.enums.CartCheckedEnum;
import top.yuyufeng.mbuy.query.GetPostageQuery;
import top.yuyufeng.mbuy.service.ICartService;
import top.yuyufeng.mbuy.service.IShippingService;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author yyf19
 */
@Controller
@RequestMapping(value = "user/{userId}/order")
public class OrderController {
    @Autowired
    private ICartService cartService;
    @Autowired
    private IShippingService shippingService;


    @RequestMapping(value = "toOrder", method = RequestMethod.GET)
    public String toPage() {
        return "order";
    }


    @RequestMapping(value = "check", method = RequestMethod.POST)
    public @ResponseBody
    ResponseJson check(@PathVariable("userId") Integer userId, @RequestBody CartDTO cartDTO) {
        cartService.check(userId,cartDTO.getId(),cartDTO.getChecked());
        return ResponseJson.success();
    }

    @RequestMapping(value = "create", method = RequestMethod.POST)
    public @ResponseBody
    ResponseJson create(@PathVariable("userId") Integer userId, @RequestBody CartDTO cartDTO) {
        System.out.println(cartDTO);
        List<CartDTO>  cartDTOList = cartService.listByUserIdWithDetailChecked(userId);
        for (CartDTO dto : cartDTOList) {

        }
        GetPostageQuery getPostageQuery = new GetPostageQuery();
        BigDecimal result = shippingService.calPostage(getPostageQuery);
        Order order = new Order();
        order.setPostage(result);
        return ResponseJson.success();
    }



}
